@extends('admin.common.base-master')

@section('html-head')
@endsection

@section('html-body')
<div id="content">
    <!-- cur-position start -->
    <div id="cur-position">
        <span class="tit">当前位置：</span>
        <a href="#">修改密码</a>
    </div>
    <!-- cur-position end -->

    <div class="fill-list">
        <span class="fill-tit">原密码：</span>
        <div class="fill-cont">
            <input class="fill-ipt" type="password" value="" placeholder="请输入旧密码" name="title" id="oldpwd">
        </div>
    </div>
    <div class="fill-list">
        <span class="fill-tit">新密码：</span>
        <div class="fill-cont">
            <input class="fill-ipt" type="password" id="newpwd" placeholder="请输入新密码" value="" name="newpwd">
        </div>
    </div>
    <div class="fill-list">
        <span class="fill-tit" id="sort">确认密码：</span>
        <div class="fill-cont">
            <input class="fill-ipt" type="password" id="checkpwd" placeholder="请再次输入新密码" value="" name="checkpwd">
        </div>
    </div>
    <div class="fill-list">
        <span class="fill-tit">&nbsp;</span>
        <div class="fill-cont">
            <input class="fill-submit" type="submit" value="修改">
        </div>
    </div>
</div>
<script>
    $(function() {
        var doc = document,
            $doc = $(doc);

        $doc.on('click','.fill-submit',function(){
            var oldpwd = $('#oldpwd').val();
            var newpwd = $('#newpwd').val();
            var checkpwd = $('#checkpwd').val();
            if(newpwd !== checkpwd){
                noty({text: "两次输入新密码不匹配", type: 'error', timeout: 600});
            }else if(newpwd.length < 6) {
                noty({text: "新密码不能少于6位", type: 'error', timeout: 600});
            }else{
                $.ajax({
                    type:"post",
                    url:"{{route('Api.Admin.Auth.changePassword')}}",
                    dataType:"json",
                    data:{"oldpassword":oldpwd,"newpassword":newpwd},
                    success:function(obj){
                        if(obj.level == "success"){
                            noty({text:obj.message,type:obj.level,timeout:800,
                                callback:{
                                    afterClose:function(){
                                        window.location.href="{{route('Admin.Home.login')}}";
                                    }
                                }
                            });
                        }else {
                            noty({
                                type: 'error',
                                text: obj.message,
                                timeout: 800
                            });
                        }
                    },
                    error:function(obj){
                        var datajson = obj.responseJSON;
                        noty({
                            type: 'error',
                            text: datajson.message,
                            timeout: 800
                        });
                    }
                });
            }
        });
    });
</script>
@endsection